package model_Ke;

import java.util.ArrayList;
import java.util.List;

public class MatrixWeight {
	private double[][] matrix;
	private int n;

	public MatrixWeight(int n) {
		matrix = new double[n][n];
		this.n = n;
		setData();
	}

	public MatrixWeight(double[][] matrix) {
		this.matrix = matrix;
		this.n = matrix.length;
	}

	public int size() {
		return n;
	}

	public void setData() {
		for (int i = 0; i < size(); i++) {
			for (int j = 0; j < size(); j++) {
				matrix[i][j] = Double.POSITIVE_INFINITY;
			}
		}
	}

	public boolean add(int row, int col, double w) {
		if (row < size() && col < size()) {
			matrix[row][col] = w;
			matrix[col][row] = w;
			return true;
		} else {
			return false;
		}
	}

	public double[][] copyMatrix() {
		double[][] result = new double[size()][size()];
		for (int i = 0; i < size(); i++) {
			for (int j = 0; j < size(); j++) {
				result[i][j] = matrix[i][j];
			}
		}
		return result;
	}

	@Override
	public String toString() {
		String temp = "\n ";
		for (int i = 0; i < size(); i++) {
			temp = temp + "\t" + i + "";
		}
		for (int i = 0; i < matrix.length; i++) {
			temp = temp + "\n" + i;
			for (int j = 0; j < matrix.length; j++) {
				if (matrix[i][j] == Double.POSITIVE_INFINITY)
					temp = temp + " \t~ ";
				else
					temp = temp + "\t" + matrix[i][j];
			}
		}
		// System.out.println(temp + "\n");
		return temp + "\n";
	}

	public double[][] getMatrix() {
		return matrix;
	}

	public void setWeight(int row, int col, double w) {
		matrix[row][col] = w;
	}

	public double getWeight(int row, int col) {
		return matrix[row][col];
	}

	public void setMatrix(double[][] matrix) {
		this.matrix = matrix;
	}

	public void setSize(int n) {
		this.n = n;
	}

}
